/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.axcc.srvaxcc.service.impl;

import com.axcc.srvaxcc.dao.LoginDao;
import com.axcc.srvaxcc.service.LoginAgentService;
import com.axcc.svraxcc.entitys.LoginAgent;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Christopher Garrido
 */
@Service
public class LoginAgentServiceImpl implements LoginAgentService {

    @Autowired
    public LoginDao loginDao;
    private static Logger log = LoggerFactory.getLogger(LoginAgentServiceImpl.class);

    @Override
    public Integer create(LoginAgent loginAgent) {
        return loginDao.create(loginAgent);
    }

    @Override
    public List allLoginDay(String dateMark) {
        return null;
    }

    @Override
    public String loginAgent(LoginAgent loginAgent) {
        Integer validAgent = validAgent(loginAgent);
        switch (validAgent) {
            case 0:
                return "agent-incorrect";
            case 10:
                loginDao.create(loginAgent);
                loginDao.loginAgent(loginAgent);
                return "agent-loginok";
            case 11:
                return "agent-alreadyon";
            default:
                return "agent-incorrect";
        }
    }

    @Override
    public Integer validAgent(LoginAgent loginAgent) {
        return loginDao.validAgent(loginAgent);
    }

    @Override
    public String unLoggedAgent(LoginAgent loginAgent) {
        Integer validAgent = validAgent(loginAgent);
        switch (validAgent) {
            case 0:
                return "agent-incorrect";
            case 11:
                loginDao.create(loginAgent);
                loginDao.unLoginAgent(loginAgent);
                return "agent-unloginok";
            case 10:
                return "agent-nologged";
            default:
                return "agent-incorrect";
        }
    }
}
